package com.wangrui.excel;

import com.alibaba.excel.EasyExcel;
import com.wangrui.pojo.Student;
import com.wangrui.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;

/**
 * @ClassName FileController
 * @Description TODO
 * @Author 王锐
 * @Date 2020/7/11 20:17
 */
@Controller
public class FileController {
    @Autowired
    private StudentService studentService;

    @RequestMapping("upload")
    @ResponseBody
    public String upload(@RequestParam("upload") MultipartFile file) throws IOException {
        EasyExcel.read(file.getInputStream(), Student.class, new UploadDataListener(studentService)).sheet().doRead();
        return "success";
    }
}
